<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        li{
            list-style: none;
            float: left;
            width: 80px;
            height: 40px;
            text-align: center;
            line-height: 40px;
            background-color: pink;
        }
        .span{
            background-color: green;
        }
        .active{
            background-color: red;
        }
    </style>
</head>
<body>
    <div id="app">
        <ul>
            <li v-for="(abc,index) in arr" :key="index" @click="dianji(index)" 
                :class="{active:abc.isActive}">
                {{abc.name}}
            </li>
            <div style="clear:both"></div>
            <p>选择了：<span class="span">{{msg}}</span></p>
        </ul>
    </div>
</body>
</html>
<script src="js/vue.min.js"></script>
<script>
    var app=new Vue({
        el:"#app",
        data:{
            arr:[
                {name:"html",isActive:false},
                {name:"css",isActive:false},
                {name:"js",isActive:false},
                {name:"vue",isActive:false}
            ],
            msg:""
        },
        methods:{
            dianji:function(index){
                this.msg=this.arr[index].name;

                //先把所有的选项背景颜色设置为默认
                for(var i=0;i<this.arr.length;i++){
                    this.arr[i].isActive=false;
                }
                //再把选中的设置为红色
                this.arr[index].isActive=true;
            }
        }
    });
</script>